* Stata SE-Standard Edition 17.0

* Replicatin file for "Voters and the IMF: Experimental Evidence from European Crisis Countries" in CPS 
* Hübscher, Sattler and Wagner 2023*
* Figures 1-3* *


clear

cd "/Users/evelyne/Library/CloudStorage/Dropbox/Fiscal Consolidation 3/Papers/Paper 3/CPS/replication/ConditionalityReplication"

cd ... 
 
log using conditionality.txt, replace


use inetdataset_main.dta

*grouping variable is "countries", "countries" differentiates between OECD (2), nonOECD (1), and countries covered by experiment (3)

* create variable to differentiate between different groups of countries (crisis, OECD, non-OECD) 

gen countries = .

replace countries = 3 if cid == 47  // Greece
replace countries = 3 if cid == 57 // Ireland
replace countries = 3 if cid == 98 // Portugal

* marking OECD Countries

gen oecd = . 

replace oecd = 1 if cid == 138 | cid == 139 | cid == 140 | cid == 147 | cid == 20 | cid == 25
replace oecd = 1 if cid == 28 | cid == 29 | cid == 154 | cid == 38 | cid == 157 | cid == 159 | cid == 153
replace oecd = 1 if cid == 54 | cid == 59 | cid == 168 | cid == 169 | cid == 170 | cid == 67 | cid == 74
replace oecd = 1 if cid == 73 | cid == 177 | cid == 79 | cid == 188 | cid == 190 |cid == 189 | cid == 97
replace oecd = 1 if cid == 111 | cid == 202 | cid == 156 | cid == 203 | cid == 119 | cid == 148 | cid == 162 | cid == 212

* marking non-OECD Countries

replace oecd = 0 if oecd == . & countries !=3

* "countries" differentiates between OECD (2), nonOECD (1), and countries covered by experiment (3)

replace countries = 1 if oecd == 0 & countries !=3
replace countries = 2 if countries == . & countries !=3

gen country = . 
replace country = 1 if cid == 47 // Greece 
replace country = 2 if cid == 57 // Ireland 
replace country = 3 if cid == 98 // Portugal
replace country = 5 if oecd == 0 & countries !=3 // Non-OECD Countries
replace country = 6 if oecd == 1 & countries !=3 // OECD Countries

*only keep variables relevant for conditionality graphs in paper (Figure 1-3)

keep if year >= 2008

drop cid DEB_IB DEB_IB_W DEB_PA DEB_PA_W DEB_QPC DEB_QPC_W DEB_SB DEB_SB_W DEB_SPC DEB_SPC_W ENV_IB ENV_IB_W ENV_PA ENV_PA_W ENV_QPC ENV_QPC_W ENV_SB ENV_SB_W ENV_SPC ENV_SPC_W EXT_IB EXT_IB_W EXT_PA EXT_PA_W EXT_QPC EXT_QPC_W EXT_SB EXT_SB_W EXT_SPC EXT_SPC_W FIN_IB FIN_IB_W FIN_PA FIN_PA_W FIN_QPC FIN_QPC_W FIN_SB FIN_SB_W FIN_SPC FIN_SPC_W FP_IB FP_IB_W FP_PA FP_PA_W FP_QPC FP_QPC_W FP_SB FP_SB_W FP_SPC FP_SPC_W INS_IB INS_IB_W INS_PA INS_PA_W INS_QPC INS_QPC_W INS_SB INS_SB_W INS_SPC INS_SPC_W LAB_IB LAB_IB_W LAB_PA LAB_PA_W LAB_QPC LAB_QPC_W LAB_SB LAB_SB_W LAB_SPC LAB_SPC_W OTH_IB OTH_IB_W OTH_PA OTH_PA_W OTH_PC OTH_PC_W OTH_QPC OTH_QPC_W OTH_SB OTH_SB_W OTH_SPC OTH_SPC_W POV_IB POV_IB_W POV_PA POV_PA_W POV_QPC POV_QPC_W POV_SB POV_SB_W POV_SPC POV_SPC_W PRI_IB PRI_IB_W PRI_PA PRI_PA_W PRI_QPC PRI_QPC_W PRI_SB PRI_SB_W PRI_SPC PRI_SPC_W RTP_IB RTP_IB_W RTP_PA RTP_PA_W RTP_QPC RTP_QPC_W RTP_SB RTP_SB_W RTP_SPC RTP_SPC_W SOE_IB SOE_IB_W SOE_PA SOE_PA_W SOE_QPC SOE_QPC_W SOE_SB SOE_SB_W SOE_SPC SOE_SPC_W SP_IB SP_IB_W SP_PA SP_PA_W SP_QPC SP_QPC_W SP_SB SP_SB_W SP_SPC SP_SPC_W IBsTOT PAsTOT SPCsTOT SBsTOT QCsDEB QCsENV QCsEXT QCsFIN QCsFP QCsINS QCsLAB QCsOTH QCsPOV QCsPRI QCsRTP QCsSOE QCsSP QCsTOT SCsDEB SCsENV SCsEXT SCsFIN SCsFP SCsINS SCsLAB SCsOTH SCsPOV SCsPRI SCsRTP SCsSOE SCsSP SCsTOT cBADEB cBAENV cBAEXT cBAFIN cBAFP cBAINS cBALAB cBAOTH cBAPOV cBAPRI cBARTP cBASOE cBASP cBATOT cQCsTOT cSCsTOT dBA1DEB dBA1ENV dBA1EXT dBA1FIN dBA1FP dBA1INS dBA1LAB dBA1OTH dBA1POV dBA1PRI dBA1RTP dBA1SOE dBA1SP dBA1TOT dBA2DEB dBA2ENV dBA2EXT dBA2FIN dBA2FP dBA2INS dBA2LAB dBA2OTH dBA2POV dBA2PRI dBA2RTP dBA2SOE dBA2SP dBA2TOT dBA3DEB dBA3ENV dBA3EXT dBA3FIN dBA3FP dBA3INS dBA3LAB dBA3OTH dBA3POV dBA3PRI dBA3RTP dBA3SOE dBA3SP dBA3TOT dQCsTOT dSCsTOT dQPCsTOT dIBsTOT dPAsTOT dSPCsTOT dSBsTOT QPCsTOT BA1DEB BA1ENV BA1EXT BA1FIN BA1FP BA1INS BA1LAB BA1OTH BA1POV BA1PRI BA1RTP BA1SOE BA1SP  BA2DEB BA2ENV BA2EXT BA2FIN BA2FP BA2INS BA2LAB BA2OTH BA2POV BA2PRI BA2RTP BA2SOE BA2SP

g id = 1

sort oecd countries year 
 
* adding up conditionalities for relevant categories: 
* - non-OECD countries
* - OECD countries
* - individual crisis countries (Greece, Portugal, Ireland)
* - time period: 2008-2014

* bys country

foreach var of varlist BA3DEB BA3ENV BA3EXT BA3FIN BA3FP BA3INS BA3LAB BA3OTH BA3POV BA3PRI BA3RTP BA3SOE BA3SP BA3TOT BA1TOT BA2TOT id {
	
	bys country: egen `var'_2014 = sum(`var') if year >=2008 & year <=2014
}

* deleting irrelevant observations

keep if year == 2014
keep ccode year countries oecd country id *_2014

gen final = . 
replace final = 1 if ccode == "GRC"
replace final = 1 if ccode == "IRL"
replace final = 1 if ccode == "PRT"
replace final = 1 if ccode == "KNA"
replace final = 1 if ccode == "FRA"

drop if final == . 

* simplify variable names (back to how they were in the original dataset)

foreach var in BA3DEB* BA3ENV* BA3EXT* BA3FIN* BA3FP* BA3INS* BA3LAB* BA3OTH* BA3POV* BA3PRI* BA3RTP* BA3SOE* BA3SP* BA3TOT* BA1TOT* BA2TOT* {
	rename  `var'_2014 `var'
	}

*input information on Spain (information from SpanishData.xlsx)

insobs 1
replace ccode = "ESP" in 6
replace year = 2014 if ccode == "ESP"
replace country = 4 if ccode == "ESP"
replace BA3DEB = 0 if ccode == "ESP"
replace BA3ENV = 0 if ccode == "ESP"
replace BA3EXT = 0 if ccode == "ESP"
replace BA3FIN = 42 if ccode == "ESP"
replace BA3FP = 0 if ccode == "ESP"
replace BA3INS = 0 if ccode == "ESP"
replace BA3LAB = 0 if ccode == "ESP"
replace BA3OTH = 0 if ccode == "ESP"
replace BA3POV = 0 if ccode == "ESP"
replace BA3PRI = 0 if ccode == "ESP"
replace BA3RTP = 0 if ccode == "ESP"
replace BA3SOE = 0 if ccode == "ESP"
replace BA3SP = 0 if ccode == "ESP"
replace BA3TOT = 42 if ccode == "ESP"
replace BA1TOT = 32 if ccode == "ESP"
replace BA2TOT = 10 if ccode == "ESP"

gen country_name = "." 
replace country_name = "Greece" if country == 1
replace country_name = "Ireland" if country == 2
replace country_name = "Portugal" if country == 3
replace country_name = "Spain" if country == 4
replace country_name = "Non OECD" if country == 5
replace country_name = "OECD" if country == 6

label var BA3DEB "Ext. Debt"
label var BA3FIN "Monetary Policy, CB, Fin. Reforms"
label var BA3FP "Fiscal Issues"
label var BA3RTP "Revenue/Taxation"
label var BA3INS "Institutional Reforms"
label var BA3LAB "Labour Issues"
label var BA3PRI "Privatization"
label var BA3SOE "State Owned Enterprises"


*Generate % of relevant policy categories*
*- using the burden of adjustment indicator BA3
*- BA3 takes into account soft and hard conditions required by the IMF
*- hard conditions are weighted more here (weighted condition count for each policy area)


*Dimensions that did not contribute towards consolidation in the countries included:
*- environment (env)
*- external sector (ext), trade
*- other
*- redistributive policies (pov)
*- social policy (sp)

egen sum_minimal = rowtotal(BA3ENV BA3EXT BA3OTH BA3POV BA3SP)
gen ba3tot_adj = BA3TOT - sum_minimal

*-Distribution (in percentage points) excluding the above mentioned policy dimensions*

gen per_ba3deb_adj = (BA3DEB*100)/ba3tot_adj
gen per_ba3fin_adj = (BA3FIN*100)/ba3tot_adj
gen per_ba3fp_adj = (BA3FP*100)/ba3tot_adj
gen per_ba3ins_adj = (BA3INS*100)/ba3tot_adj
gen per_ba3lab_adj = (BA3LAB*100)/ba3tot_adj
gen per_ba3pri_adj = (BA3PRI*100)/ba3tot_adj
gen per_ba3rtp_adj = (BA3RTP*100)/ba3tot_adj
gen per_ba3soe_adj = (BA3SOE*100)/ba3tot_adj

*labeling variables*

label var per_ba3deb_adj "Ext. Debt"
label var per_ba3fin_adj "Monetary Policy, CB, Fin. Reforms"
label var per_ba3fp_adj "Fiscal Issues"
label var per_ba3rtp_adj "Revenue/Taxation"
label var per_ba3ins_adj "Institutional Reforms"
label var per_ba3lab_adj "Labour Issues"
label var per_ba3pri_adj "Privatization"
label var per_ba3soe_adj "State Owned Enterprises"


***Combining similar categories**
*- Fiscal policy and Revenue and tax issues (FP, RTP)
*- State owned enterprises and privatization (SOE, PRI)

egen fp_rtp = rowtotal(BA3FP BA3RTP)
egen soe_pri = rowtotal(BA3PRI BA3SOE)

gen per_ba3deb_adj2 = (BA3DEB*100)/ba3tot_adj
gen per_ba3fin_adj2 = (BA3FIN*100)/ba3tot_adj
gen per_ba3fprtp_adj2 = (fp_rtp*100)/ba3tot_adj
gen per_ba3ins_adj2 = (BA3INS*100)/ba3tot_adj
gen per_ba3lab_adj2 = (BA3LAB*100)/ba3tot_adj
gen per_ba3soepri_adj2 = (soe_pri*100)/ba3tot_adj

label var per_ba3soepri_adj2 "Privatization/SOE"
label var per_ba3fprtp_adj2 "Fiscal Issues, Revenue, & Taxation"

gen soft = (BA1TOT*100)/BA3TOT
gen hard = (BA2TOT*100)/BA3TOT

sort country

**********
*FIGURE 1*
**********

*Soft vs. Hard Conditions (comparison btw countries covered in analysis, OECD and non OECD countries)

#delimit; 
graph hbar soft hard, over(country, relabel(1 "Greece" 2 "Ireland" 3 "Portugal" 4 "Spain" 5 "Non OECD" 6 "OECD") label(labsize(3))) stack 
bar(1, color(176 196 222)) bar(2, color(178 34 34)) 
yscale(range(0(10)100))
ylabel(0(20)100, labsize(3))
blabel(bar, position(center) format(%9.0f) size(2.5))
ytitle("Proportion of Soft vs. Hard Conditions (%)", size(3))
legend(pos(6) lab(1 "Soft conditions") lab(2 "Hard conditions") size(2.5) row(1)) saving(Figure1.gph, replace); 

graph export Figure1.pdf, replace


**********
*FIGURE 3*
**********

*Total number of absolute conditions (comparison btw Greece, Ireland, Portugal and Spaion)*
*******************************************************************************************

gen europe_countries = .
replace europe_countries = 1 if country == 1
replace europe_countries = 2 if country == 2
replace europe_countries = 3 if country == 3
replace europe_countries = 4 if country == 4

#delimit; 
graph bar fp_rtp BA3DEB BA3FIN  BA3INS BA3LAB soe_pri, over(europe_countries, relabel(1 "Greece" 2 "Ireland" 3 "Portugal" 4 "Spain") label(labsize(3.5))) 
bar(1, color(240 128 128)) bar(2, color(205 34 34)) bar(3, color(160 27 16)) bar(4, color(173 216 230)) bar(5, color(0 206 209)) bar(6, color(0 139 139))
ylabel(, labsize(2.5))
ytitle("Number of Reform Issues / Policy Domain", size(3.5)) 
legend(pos(6) lab(1 "Fiscal Issues (Revenue/Taxes)") lab(2 "External Debt") lab(3 "Monetary Policy, CB, Fin. Reforms")  lab(4 "Institutional Reforms") lab(5 "Labor Issues") lab(6 "Privatization/SOE") row(2) size(3)) saving(Figure3.gph, replace);

graph export Figure3.pdf, replace


**********
*FIGURE 2*
**********

* to use twoway command (-> more flexibility to shape bars) create new policy dimension variables
* - different categories add up to 100 (category entries express the sum of categories)
*-this allows to plot areas that add up to 100 in a twodimensional space defined by x-axis (percentage) and y-axis (countries)
*for more information see: https://blog.uvm.edu/tbplante/2018/03/13/making-a-horizontal-stacked-bar-graph-with-graph-twoway-rbar-in-stata/


gen Bottom = 0.1
gen fiscal  = per_ba3fprtp_adj2
gen debt = per_ba3fprtp_adj2 + per_ba3deb_adj
gen monetary = per_ba3fprtp_adj2 + per_ba3deb_adj + per_ba3fin_adj
gen institution = per_ba3fprtp_adj2 + per_ba3deb_adj + per_ba3fin_adj + per_ba3ins_adj
gen labor = per_ba3fprtp_adj2 + per_ba3deb_adj + per_ba3fin_adj + per_ba3ins_adj + per_ba3lab_adj
gen privatization = 100

#delimit; 
graph twoway 
(rbar Bottom fiscal country, horizontal barwidth(.6) color("240 128 128")) 
(rbar fiscal debt country, horizontal barwidth(.6) color("205 34 34")) 
(rbar debt monetary country, horizontal barwidth(.6) color("139 0 0")) 
(rbar monetary institution country, horizontal barwidth(.6)  color("173 216 230")) 
(rbar institution labor country, horizontal barwidth(.6) color("0 206 209")) 
(rbar labor privatization country, horizontal barwidth(.6) color("0 139 139")) 
, 
yla(1 "Greece" 2 "Ireland" 3 "Portugal" 4 "Spain" 5 "Non OECD" 6 "OECD")
yline(4.5)
ytitle("") 
xtitle("Percentage", size(3))
legend(pos(6) lab(1 "Fiscal Issues (Revenue/Taxes)") lab(2 "External Debt") lab(3 "Monetary Policy, CB, Fin. Reforms")  lab(4 "Institutional Reforms") lab(5 "Labor Issues") lab(6 "Privatization/SOE") row(2) size(2.5)) saving(Figure2.gph, replace);

graph export Figure2.pdf, replace
